﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Orange.Lib.Effective
{
    /// <summary>
    /// 理解接口方法和虚方法的不同
    /// </summary>
    namespace MethodUse
    {
        interface IMsg
        {
            void Message();
        }

        #region Not recommend


        public class MyClass : IMsg
        {

            public void Message()
            {
                Console.WriteLine("MyClass");
            }
        }

        public class MyDerivedClass : MyClass
        {
            public new void Message()
            {
                Console.WriteLine("MyDerivedClass");
            }
        }
        #endregion

        #region Recommend
        public class MyClass2 : IMsg
        {
            public virtual void Message()
            {
                Console.WriteLine("MyClass2");
            }
        }

        public class MyDerivedClass2 : MyClass2
        {
            public override void Message()
            {
                Console.WriteLine("MyDerivedClass2");
            }
        }
        #endregion
    }
}
